using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using NBear.Common;
using NBear.Data;

namespace NBear.Test.temp
{
    #region _Entity Definition

    namespace Scope_OneTableOneExtendedTable
    {
        [Table("PrivilegeOwner")]
        public interface PrivilegeOwnerExtended : IEntity
        {
            [PrimaryKey]
            int Id { get; }
            string Name { get; set; }
        }

        [Table("PrivilegeOwner", IsView=true)]
        public interface PrivilegeOwner : PrivilegeOwnerExtended
        {
        }

        [Table("User")]
        public interface UserExtended : IEntity
        {
            [PrimaryKey]
            int Id { get; }
        }

        [Table("select * from User inner join PrivilegeOwner on PrivilegeOwner.Id = [User].Id", IsView=true)]
        public interface User : UserExtended, PrivilegeOwnerExtended
        {
        }

        [Table("LocalUser")]
        public interface LocalUserExtended : IEntity
        {
            [PrimaryKey]
            int Id { get; }
            string LoginId { get; set; }
            string Password { get; set; }
        }

        [Table("select * from LocalUser inner join User on [User].Id = LocalUser.Id inner join PrivilegeOwner on PrivilegeOwner.Id = LocalUser.Id", IsView=true)]
        public interface LocalUser : LocalUserExtended, User
        {
            [PrimaryKey]
            new int Id { get; }
        }

        [Table("AgentUser")]
        public interface AgentUserExtended : IEntity
        {
            [PrimaryKey]
            int Id { get; }
            string LoginId { get; set; }
        }

        [Table("select * from AgentUser inner join [User] on [User].Id = AgentUser.Id inner join PrivilegeOwner on PrivilegeOwner.Id = AgentUser.Id", IsView = true)]
        public interface AgentUser : AgentUserExtended, User
        {
            [PrimaryKey]
            new int Id { get; }
        }

        [Table("GhostUser")]
        public interface GhostUserExtended : IEntity
        {
            [PrimaryKey]
            int Id { get; }
        }

        [Table("select * from GhostUser inner join [User] on [User].Id = GhostUser.Id inner join PrivilegeOwner on PrivilegeOwner.Id = GhostUser.Id", IsView=true)]
        public interface GhostUser : GhostUserExtended, User
        {
            [PrimaryKey]
            new int Id { get; }
        }

        [Table("UserGroup")]
        public interface UserGroupExtended : IEntity
        {
            [PrimaryKey]
            int Id { get; }
            string Comment { get; set; }
        }

        [Table("select * from UserGroup inner join PrivilegeOwner on PrivilegeOwner.Id = UserGroup.Id", IsView=true)]
        public interface UserGroup : UserGroupExtended, PrivilegeOwner
        {
            [PrimaryKey]
            new int Id { get; }
        }
    }

    namespace Scope_OneTableOneExtendedTable_RefactoredWithInterfaceContract
    {
        [Table(IsContract=true)]
        public interface IdentableEntity : IEntity
        {
            [PrimaryKey]
            int Id { get; set; }
            string Name { get; set; }
        }

        [Table(IsContract = true)]
        public interface Loginable : IEntity
        {
            string LoginId { get; set; }
        }

        [Table(IsContract = true)]
        public interface PasswordLoginable : Loginable
        {
            string Password { get; set; }
        }

        [Table(IsContract = true)]
        public interface PrivilegeAssignable : IEntity
        {
            int PrivilegeOwnerId { get; set; }
        }

        [Table("User", UpdateTableName="User", IsCascadeUpdate=true)]
        public interface User : IdentableEntity, PrivilegeAssignable
        {
        }

        [Table("select [User].*, LocalUser.LoginId, LocalUser.Password from LocalUser inner join [User] on LocalUser.Id = [User].Id", UpdateTableName = "LocalUser", IsView = true, IsCascadeUpdate = true)]
        public interface LocalUser : PasswordLoginable, User
        {
        }

        [Table("select [User].*, AgentUser.LoginId from AgentUser inner join [User] on AgentUser.Id = [User].Id", UpdateTableName = "AgentUser", IsView = true, IsCascadeUpdate = true)]
        public interface AgentUser : Loginable, User
        {
        }

        [Table("select [User].* from GhostUser inner join [User] on GhostUser.Id = [User].Id", UpdateTableName = "GhostUser", IsView = true, IsCascadeUpdate = true)]
        public interface GhostUser : User
        {
        }

        [Table("UserGroup", UpdateTableName = "UserGroup", IsCascadeUpdate=true)]
        public interface UserGroup : IdentableEntity, PrivilegeAssignable
        {
            string Comment { get; set; }
        }
    }

    #endregion

    /// <summary>
    /// Summary description for TestInheritence
    /// </summary>
    [TestClass]
    public class TestInheritence
    {
        public TestInheritence()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestMethod1()
        {
            //
            // TODO: Add test logic	here
            //
        }
    }
}
